package com.runen.infinitemovement.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.runen.infinitemovement.R;
import com.runen.infinitemovement.activity.MyTeamActivityV2;
import com.runen.infinitemovement.adapter.LikeListAdapter;
import com.runen.infinitemovement.model.api.CompanyAPI;
import com.runen.infinitemovement.model.entity.LikeListEntity;
import com.runen.rxnetlibrary.net.callback.BaseResultCallback;
import com.runen.rxnetlibrary.utils.ToastUtils;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Create by LiaoDuanHong
 * Create on
 */
public class DynamicFragment extends Fragment {
    @BindView(R.id.rcv_content)
    RecyclerView rcv_content;
    private View view;

    public static Fragment newInstance() {
        Fragment fragment = new DynamicFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (null == view) {
            view = inflater.inflate(R.layout.fragment_dynamic, container, false);
            ButterKnife.bind(this, view);
        }
        return view;
    }

    public void initData() {
        Map<String, Object> params = new HashMap<>();
        params.put("tenantId", ((MyTeamActivityV2) getActivity()).entity.team.companyId);
        new CompanyAPI().likeListRecord(params, new BaseResultCallback<LikeListEntity>() {
            @Override
            public void onResponse(LikeListEntity response) {
                if (response.code == 0) {
                    if (response.data != null) {
                        LinearLayoutManager llm = new LinearLayoutManager(getActivity());
                        rcv_content.setLayoutManager(llm);
                        LikeListAdapter adapter = new LikeListAdapter(getActivity());
                        rcv_content.setAdapter(adapter);
                        adapter.setNewInstance(response.data);
                    }
                } else {
                    ToastUtils.showShort(response.msg);
                }
            }
        });
    }
}
